const fs = require("fs")
const { resolve } = require("path")

module.exports.patchRequire = (folder, cb) => {
  const Root = resolve(__dirname, "../" + folder)
  const files = fs.readdirSync(Root)
  const blocks = {}
  for (let v of files) {
    if (v === "index.js") continue
    const Path = resolve(__dirname, Root, `./${v}`)
    const block = require(Path)
    cb && cb(block)
    const blockName = v.replace(/.js$/, '')
    blocks[blockName] = block
  }
  return blocks
}
